*Bartek Woda woda@uchicago.edu

*Notes: Thanks to Bartek Woda (woda@uchicago.edu) for writing this code. 
*Treating Yugoslavia as Serbia, West Germany as Germany and Czechoslovakia as Czech Republic for purposes of Fig.2 
*Misssing from map: Cook Islands, Cayman Islands, Western Sahara, Macao, Montserrat, Niue, Palestine. These are also not in the template but have PTAs
*Explain sum
*Labels of some vars
*Explain EU; France vs EU issue

*Fig. 1 - total PTAs over time

	use "CCL_PTA_Data_Ver1", clear
	cap drop _*

	egen uniquepta=tag(pta_number)
	gen uniqueptacoded=uniquepta*coded

	collapse (sum) uniquepta uniqueptacoded, by(year_signed)
	sort year_signed
	gen uniqueptasum=sum(uniquepta)
	gen uniqueptacodedsum=sum(uniqueptacoded)

	#delimit ;
		
		twoway (line uniqueptasum year_signed, lc(black)) (line uniqueptacodedsum year_signed, lc(gs4) lp(dash)),
			xlab(1945(5)2010, angle(45) labsize(*0.8)) xt("Year") ylab(0(100)800, angle(0) labsize(*0.8))
			yt("Cumulative Number of PTAs") legend(order(1 "All PTAs" 2 "PTAs in Our Sample")) graphregion(color(white))
			name(Fig_1, replace); 
			
	#delimit cr

	
*Fig. 2 - map of PTAs by country

	use "oldworlddb_plus", clear
	
	drop if (COWSYEAR>2010 | COWEYEAR<2010)
	
	ren ISO1AL3 iso3c
	replace iso3c="FRO" if CNTRY_NAME=="Faroe Islands"
	replace iso3c="GRL" if CNTRY_NAME=="Greenland"
	replace iso3c="HKG" if CNTRY_NAME=="Hong Kong"
	replace iso3c="JEY" if CNTRY_NAME=="Jersey"
	replace iso3c="KSV" if CNTRY_NAME=="Kosovo"
	
	tempfile mapdb
	save `mapdb'

	use "CCL_PTA_Data_Ver1", clear
	cap drop _*
	
	collapse (count) coded, by(iso3c)
	
	merge 1:1 iso3c using `mapdb'
	replace coded=0 if _m==2
	drop if _m==1
	
	#delimit;
	
	spmap coded using "oldworldcoord_plus", 
		polygon(d("worldcoord") select(keep if _ID==59)) id(_ID)
		clm(custom) clb(0 5 10 15 20 25 10000)
		fcolor("255 255 255" "255 255 204" "161 218 180" "65 182 196" "44 127 184" "37 52 148") 
		legtitle("Total PTAs") name(Fig_2, replace)
		legend(label(2 "0-5") label(3 "6-10") label(4 "11-15") label(5 "16-20")
		label(6 "21-25") label(7 ">25") pos(8) symy(5) symx(5) textw(10) size(3));
		
	#delimit cr	
		
	
*Fig. 3 - % of PTAs with competition chapters or articles

	use "CCL_PTA_Data_Ver1", clear
	cap drop _*

	egen uniquepta=tag(pta_number)
	gen uniqueptacoded=uniquepta*coded
	keep if uniqueptacoded==1
	gen chapter_article = 0
	replace chapter_article = 1 if chapter==1 | article==1
	
	collapse (sum) uniqueptacoded chapter article comp_any comp_other chapter_article , by(year_signed)
	sort year_signed
	
	foreach var in uniqueptacoded chapter article comp_any comp_other chapter_article {
	
		gen `var'sum=sum(`var')
	
	}
	
	gen chapter_share=chaptersum/uniqueptacodedsum
	gen article_share=articlesum/uniqueptacodedsum
    gen chapter_article_share= chapter_articlesum/uniqueptacodedsum

	

	#delimit ;
		
			
			twoway (line chapter_article_share year_signed, lc(black)),
			xlab(1945(5)2010, angle(45) labsize(*0.8)) xt("Year") ylab(0(0.05)0.7, angle(0) labsize(*0.8))
			yt("Share of PTAs")  graphregion(color(white))
			name(Fig_3, replace); 
			
	#delimit cr
	
*Fig. 4 - % of PTAs with competition law or agency requirements

	use "CCL_PTA_Data_Ver1", clear
	cap drop _*

	egen uniquepta=tag(pta_number)
	gen uniqueptacoded=uniquepta*coded
	keep if uniqueptacoded==1

	tab  law_req agency_req
	
	collapse (sum) uniqueptacoded law_req agency_req, by(year_signed)
	sort year_signed
	
	foreach var in uniqueptacoded law_req agency_req{
	
		gen `var'sum=sum(`var')
	
	}
	
	gen law_req_share=law_reqsum/uniqueptacodedsum
	gen agency_req_share=agency_reqsum/uniqueptacodedsum

	#delimit ;
		
		twoway (line law_req_share year_signed, lc(black)) (line agency_req_share year_signed, lc(gs4) lp(dash)),
			xlab(1945(5)2010, angle(45) labsize(*0.8)) xt("Year") ylab(0(0.05)0.5, angle(0) labsize(*0.8))
			yt("Share of PTAs") legend(order(1 "Law requirement" 2 "Agency requirement")) graphregion(color(white))
			name(Fig_4, replace); 
			
	#delimit cr

	
*Fig. 5 - Topics Coveredf in PTAs

	use "CCL_PTA_Data_Ver1", clear
	cap drop _*

	egen uniquepta=tag(pta_number)
	gen uniqueptacoded=uniquepta*coded
	keep if uniqueptacoded==1 & (chapter==1 | article==1)
	
	gen all4 = dominance + cartels + mergers +vertical
	tab all4 

	gen all3 = dominance + cartels + vertical
		tab all3 
	
	collapse (sum) uniqueptacoded dominance cartels mergers vertical, by(year_signed)
	sort year_signed
	
	foreach var in uniqueptacoded dominance cartels mergers vertical{
	
		gen `var'sum=sum(`var')
		gen `var'_share=`var'sum/uniqueptacodedsum
	
	}

	#delimit ;
		
		twoway (line dominance_share year_signed, lc(black)) (line cartels_share year_signed, lc(gs4) lp(dash))
			(line mergers_share year_signed, lc(gs7) lp(longdash)) (line vertical_share year_signed, lc(gs10) lp(dot)),
			xlab(1945(5)2010, angle(45) labsize(*0.8)) xt("Year") ylab(0(0.1)1, angle(0) labsize(*0.8))
			yt("Share of PTAs with a Competion Chapter or Article", size(*0.8)) 
			legend(order(1 "Dominance" 2 "Cartels" 3 "Mergers" 4 "Vertical agreements"))
			graphregion(color(white)) name(Fig_5, replace); 
			
	#delimit cr

*Fig. 6 - % of PTAs with MFN and national treatment provisions

	use "CCL_PTA_Data_Ver1", clear
	cap drop _*

	egen uniquepta=tag(pta_number)
	gen uniqueptacoded=uniquepta*coded
	keep if uniqueptacoded==1 & (chapter==1 | article==1)

	tab nat_treat mfn
	
	collapse (sum) uniqueptacoded nat_treat mfn, by(year_signed)
	sort year_signed
	
	foreach var in uniqueptacoded nat_treat mfn{
	
		gen `var'sum=sum(`var')
		gen `var'_share=`var'sum/uniqueptacodedsum
		
	}

	#delimit ;
		
		twoway (line nat_treat_share year_signed, lc(black)) (line mfn_share year_signed, lc(gs4) lp(dash)),
			xlab(1945(5)2010, angle(45) labsize(*0.8)) xt("Year") ylab(0(0.1)1, angle(0) labsize(*0.8))
			yt("Share of PTAs with a Competion Chapter or Article", size(*0.8))
			legend(order(1 "National treatment" 2 "Most favored nation")) graphregion(color(white))
			name(Fig_6, replace); 
			
	#delimit cr
	
*Fig. 7 - % of PTAs with cooperation provisions

	use "CCL_PTA_Data_Ver1", clear
	cap drop _*

	egen uniquepta=tag(pta_number)
	gen uniqueptacoded=uniquepta*coded
	keep if uniqueptacoded==1 & (chapter==1 | article==1)

	
	gen all = convergence+ notify+info_exc+tech_ass +neg_comity + pos_comity +working_group+consult+common_auth
	tab all
	
	collapse (mean) uniqueptacoded convergence notify info_exc tech_ass neg_comity ///
		pos_comity working_group consult common_auth
		
	ren convergence-common_auth v=
	reshape long v, i(unique) j(var) str
	sort v
	gen n=_n
	lab def pta_provs 1 "Negative Comity" 2 "Technical Assistance" 3 "Convergence" ///
		4 "Positive Comity" 5 "Notification" 6 "Common Authority" 7 "Information Exchange" ///
		8 "Consultation" 9 "Working Group"
	lab val n pta_provs

	#delimit ;
		
	twoway bar v n, xlab(1(1)9, val angle(45) labsize(*0.8)) ylab(0(0.1)1, angle(0) labsize(*0.8) gmax)
		xt("") yt("Share of PTAs with a Competion Chapter or Article", size(*0.8)) graphregion(color(white)) name(Fig_7, replace);
			
	#delimit cr
	
	
*Fig. 8 - % of PTAs with dispute settlement mechanisms

	use "CCL_PTA_Data_Ver1", clear
	cap drop _*

	egen uniquepta=tag(pta_number)
	gen uniqueptacoded=uniquepta*coded
	keep if uniqueptacoded==1 & (chapter==1 | article==1)

	collapse (sum) uniqueptacoded dsm_pta_comp, by(year_signed)
	sort year_signed
	
	foreach var in uniqueptacoded dsm_pta_comp{
	
		gen `var'sum=sum(`var')
	
	}
	
	gen dsm_pta_comp_share=dsm_pta_compsum/uniqueptacodedsum

	#delimit ;
		
		twoway (line dsm_pta_comp_share year_signed, lc(black)),
			xlab(1945(5)2010, angle(45) labsize(*0.8)) xt("Year") ylab(0(0.1)1, angle(0) labsize(*0.8))
			yt("Share of PTAs with a Competion Chapter or Article", size(*0.8)) graphregion(color(white))
			name(Fig_8, replace); 
			
	#delimit cr
	
	
*Fig. 9 - % of PTAs with EU or US memberships

	use "CCL_PTA_Data_Ver1", clear
	cap drop _*
	
	egen uniquepta=tag(pta_number)
	gen uniqueptacoded=uniquepta*coded
	gen uniquepta_ch_art=uniqueptacoded*(chapter==1 | article==1)
	gen EU_flag_ch_art=EU_flag*uniquepta_ch_art
	gen US_flag_ch_art=US_flag*uniquepta_ch_art
	keep if uniquepta==1
	
	collapse (sum) uniquepta uniqueptacoded uniquepta_ch_art EU_flag US_flag ///
		EU_flag_ch_art US_flag_ch_art, by(year_signed)
		
	sort year_signed 
	
	foreach var of varlist uniquepta uniqueptacoded uniquepta_ch_art EU_flag US_flag ///
		EU_flag_ch_art US_flag_ch_art {
	
		gen `var'sum=sum(`var')
		
	}	
	
	gen US_share_all=US_flagsum/uniqueptasum
	gen EU_share_all=EU_flagsum/uniqueptasum
	gen US_share_ch_art=US_flag_ch_artsum/uniquepta_ch_artsum
	gen EU_share_ch_art=EU_flag_ch_artsum/uniquepta_ch_artsum
	
	#delimit ;
		
		twoway (line US_share_all year_signed, lc(black)) (line EU_share_all year_signed, lc(gs4) lp(dash))
			(line US_share_ch_art year_signed, lc(gs7) lp(longdash)) (line EU_share_ch_art year_signed, lc(gs10) lp(dash_dot)),
			xlab(1945(5)2010, angle(45) labsize(*0.8)) xt("Year") ylab(0(0.1)1, angle(0) labsize(*0.8))
			yt("Share of PTAs", size(*0.7)) legend(order(1 "U.S. PTAs" 2 "EU PTAs"
			3 "U.S. PTAs with competition chapter/article" 4 "EU PTAs with competition chapter/article") size(*0.6))
			graphregion(color(white)) name(Fig_9, replace); 
			
	#delimit cr
	
*Fig. 10 -- PTAs with Distintively EU or US Langauge

	use "CCL_PTA_Data_Ver1", clear
	cap drop _*
	
	egen uniquepta=tag(pta_number)
	gen uniqueptacoded=uniquepta*coded
	keep if uniqueptacoded==1 & (chapter==1 | article==1)
	
	collapse (sum) uniqueptacoded law_eu law_us, by(year_signed)
	sort year_signed	
	
	foreach var in uniqueptacoded law_eu law_us {
	
		gen `var'sum=sum(`var')
		gen `var'_share=`var'sum/uniqueptacodedsum
		
	}

	#delimit ;
		
		twoway (line law_eu_share year_signed, lc(black)) (line law_us_share year_signed, lc(gs4) lp(dash)),
			xlab(1945(5)2010, angle(45) labsize(*0.8)) xt("Year") ylab(0(0.1)1, angle(0) labsize(*0.8))
			yt("Share of PTAs with a Competion Chapter or Article", size(*0.8))
			legend(order(1 "European language" 2 "American language")) graphregion(color(white))
			name(Fig_10, replace); 
			
	#delimit cr
	
*Fig. 11 - PTAs with Distintively EU Langauge btoken out by EU Participation

	use "CCL_PTA_Data_Ver1", clear
	cap drop _*
	
	egen uniquepta=tag(pta_number)
	gen uniqueptacoded=uniquepta*coded
	gen nonEU_flag=1-EU_flag
	gen law_eu_EU_flag=EU_flag*law_eu
	gen law_eu_nonEU_flag=nonEU_flag*law_eu
	keep if uniqueptacoded==1 & (chapter==1 | article==1)
	
	collapse (sum) uniqueptacoded EU_flag nonEU_flag law_eu law_eu_EU_flag law_eu_nonEU_flag, by(year_signed)
	sort year_signed	
	
	foreach var in EU_flag nonEU_flag law_eu_EU_flag law_eu_nonEU_flag {
	
		gen `var'sum=sum(`var')
		
	}
	
	gen law_eu_EU_flag_share=law_eu_EU_flagsum/EU_flagsum
	gen law_eu_nonEU_flag_share=law_eu_nonEU_flagsum/nonEU_flagsum
	
	#delimit ;
		
		twoway (line law_eu_EU_flag_share year_signed, lc(black)) (line law_eu_nonEU_flag_share year_signed, lc(gs4) lp(dash)),
			xlab(1945(5)2010, angle(45) labsize(*0.8)) xt("Year") ylab(0(0.1)1, angle(0) labsize(*0.8))
			yt("Share of PTAs with a Competion Chapter or Article", size(*0.8))
			legend(order(1 "EU PTAs" 2 "Non-EU PTAs")) graphregion(color(white))
			name(Fig_11, replace); 
			
	#delimit cr
	
*Fig. 12 -- PTAs with Distintively US Langauge btoken out by US Participation

	use "CCL_PTA_Data_Ver1", clear
	cap drop _*
	
	egen uniquepta=tag(pta_number)
	gen uniqueptacoded=uniquepta*coded
	gen nonUS_flag=1-US_flag
	gen law_us_US_flag=US_flag*law_us
	gen law_us_nonUS_flag=nonUS_flag*law_us
	keep if uniqueptacoded==1 & (chapter==1 | article==1)
	
	collapse (sum) uniqueptacoded US_flag nonUS_flag law_us law_us_US_flag law_us_nonUS_flag, by(year_signed)
	sort year_signed	
	
	foreach var in US_flag nonUS_flag law_us_US_flag law_us_nonUS_flag {
	
		gen `var'sum=sum(`var')
		
	}
	
	gen law_us_US_flag_share=law_us_US_flagsum/US_flagsum
	gen law_us_nonUS_flag_share=law_us_nonUS_flagsum/nonUS_flagsum
	
	#delimit ;
		
		twoway (line law_us_US_flag_share year_signed, lc(black)) (line law_us_nonUS_flag_share year_signed, lc(gs4) lp(dash)),
			xlab(1945(5)2010, angle(45) labsize(*0.8)) xt("Year") ylab(0(0.1)1, angle(0) labsize(*0.8))
			yt("Share of PTAs with a Competion Chapter or Article", size(*0.8))
			legend(order(1 "U.S. PTAs" 2 "Non-U.S. PTAs")) graphregion(color(white))
			name(Fig_12, replace); 
			
	#delimit cr
		
*Numbers for the draft

	use "CCL_PTA_Data_Ver1", clear
	egen uniquepta=tag(pta_number) // unique PTA
	gen uniqueptacoded=uniquepta*coded // unique coded PTA
	gen uniquepta_ch_art=uniqueptacoded*(chapter==1 | article==1) // uniqie PTA with chapter/article
	
	*Number of competition chapters
	
	tab chapter if uniqueptacoded==1
	
	*Number of competition articles
	
	tab article if uniqueptacoded==1
	
	*Number of antitrust mentions not in an article or chapter
	
	tab comp_any comp_other if uniqueptacoded==1 & article!=1 & chapter!=1

	
	*Mutually exclusive
	
	tab chapter article if uniqueptacoded==1
	
	
	*First PTA with law_req
	
	sort year_signed
	list year_signed pta_name if law_req==1 & uniqueptacoded==1
	
	*First PTA with agency_req
	
	sort year_signed
	list year_signed pta_name if agency_req==1 & uniqueptacoded==1	
	
	*Both law_req and agency_req 
	
	tab law_req agency_req if uniqueptacoded==1, cell
	
	*Dominance
	
	tab dominance if uniquepta_ch_art==1
	tab cartels if uniquepta_ch_art==1
	tab mergers if uniquepta_ch_art==1
	tab vertical if uniquepta_ch_art==1
	
	gen all_four=0
	replace all_four = 1 if dominance==1 & cartels==1 & mergers==1 & vertical==1 
	tab all_four if uniquepta_ch_art==1
	
	*National treatment
	
	tab nat_treat if uniquepta_ch_art==1
	
	*Most favored nation
	
	tab mfn if uniquepta_ch_art==1
	
	tab nat_treat mfn if uniquepta_ch_art==1
	
	
	*Negative comity, technical assistance, etc.
	
	foreach var of varlist 	convergence notify info_exc tech_ass neg_comity ///
		pos_comity working_group consult common_auth {
	
		tab `var' if uniquepta_ch_art==1
		
	}
	
	*Dispute settlement
	
	tab dsm_pta_comp if uniquepta_ch_art==1
	
	*EU and US agreements
	
	tab EU_flag if uniquepta==1 //coded+uncoded
	tab US_flag if uniquepta==1 //coded+uncoded
	
	tab EU_flag if uniquepta_ch_art==1 // chapter/article
	tab US_flag if uniquepta_ch_art==1 // chapter/article
	
	*European/US language
	
	tab law_eu if uniquepta_ch_art==1
	tab law_us if uniquepta_ch_art==1
	
	tab law_eu if uniquepta_ch_art==1 & EU_flag==1 //of those where EU is a party
	tab law_eu if uniquepta_ch_art==1 & EU_flag==0 //of those where EU is NOT a party
	tab law_us if uniquepta_ch_art==1 & US_flag==1 //of those where US is a party
	tab law_us if uniquepta_ch_art==1 & US_flag==0 //of those where US is NOT a party

	
